package com.lc.baselib.net.intercept;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * @author LiuChao
 * @describe
 * @date 2018/6/25
 * @contact email:450127106@qq.com
 */
public class NetworkIntercept implements Interceptor {
    private GlobalHttpHandler mGlobalHttpHandler;

    public NetworkIntercept(GlobalHttpHandler globalHttpHandler) {
        mGlobalHttpHandler = globalHttpHandler;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        Response response = chain.proceed(request);
        //打印响应结果
        //String bodyString = printResult(request, response.newBuilder().build(), logResponse);
        //这里可以比客户端提前一步拿到服务器返回的结果,可以做一些操作,比如token超时,重新获取
        if (mGlobalHttpHandler != null)
            return mGlobalHttpHandler.onHttpResultResponse("", chain, response);
        return response;
    }
}
